package com.dhwl.hsh.merchant.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dhwl.hsh.merchant.R;
import com.dhwl.hsh.lib.bean.Address;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 简要描述
 *
 * @author Derek.Kidd
 * @version V1.0.0
 * @date 2016-04-25 16:27
 */
public class TaskAddressAdapter extends BaseAdapter<Address> {


    public TaskAddressAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_layout_address, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Address address = getList().get(position);
        if (0 == position) {
            viewHolder.iconShippingAddress.setImageResource(R.drawable.icon_start_address);
            viewHolder.tvShippingAddress.setText(R.string.start_shipping_add);
        } else {
            viewHolder.iconShippingAddress.setImageResource(R.drawable.icon_end_address);
            viewHolder.tvShippingAddress.setText(R.string.end_shipping_add);
        }
        if(!TextUtils.isEmpty(address.getPosiName()))
        {
            viewHolder.tvShippingAddressValue.setText(address.getPosiName());
        }else{
            viewHolder.tvShippingAddressValue.setText("");
        }
        if(!TextUtils.isEmpty(address.getLinkManMobile()))
        {
            viewHolder.tvPhoneValue.setText(address.getLinkManMobile());
        }else{
            viewHolder.tvPhoneValue.setText("");
        }
        return convertView;
    }

    static class ViewHolder {
        /**
         * 右侧小图标
         */
        @Bind(R.id.icon_shipping_address)
        ImageView iconShippingAddress;
        /**
         * 发货地 or 配送地
         */
        @Bind(R.id.tv_shipping_address)
        TextView tvShippingAddress;
        /**
         * 发货地 or 配送地  的值
         */
        @Bind(R.id.tv_shipping_address_value)
        TextView tvShippingAddressValue;
        /**
         * 发货地 or 配送地 对应的手机号
         */
        @Bind(R.id.tv_phone_value)
        TextView tvPhoneValue;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
